/**
 * 生成器工具
 */

class Generator {
  /**
   * 生成Token
   */
  static generateToken(userId) {
    const timestamp = Date.now()
    const randomStr = Math.random().toString(36).substring(2, 15)
    return `${userId}_${timestamp}_${randomStr}`
  }

  /**
   * 生成6位数字验证码
   */
  static generateVerifyCode() {
    return Math.floor(100000 + Math.random() * 900000).toString()
  }

  /**
   * 生成邀请码（8位字母数字组合）
   */
  static generateInviteCode() {
    const chars = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ' // 去掉容易混淆的I、O
    let result = ''
    for (let i = 0; i < 8; i++) {
      result += chars.charAt(Math.floor(Math.random() * chars.length))
    }
    return result
  }

  /**
   * 随机选择头像
   */
  static randomAvatar() {
    const avatars = ['avatar-1.png', 'avatar-2.png', 'avatar-3.png', 'avatar-4.png', 'avatar-5.png']
    const shuffled = avatars.sort(() => Math.random() - 0.5)
    return `static/${shuffled[0]}`
  }
}

module.exports = Generator

